package cn.cs.service.impl;

import cn.cs.client.CsRoleClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.CsMenuRole;
import cn.cs.pojo.CsRole;
import cn.cs.service.CsRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CsRoleServiceImpl implements CsRoleService {

    @Resource
    private CsRoleClient roleClient;

    public CsRole getCsRoleById(Long id) throws Exception {
        return roleClient.getCsRoleById(id);
    }

    public List<CsRole> getCsRoleListByMap(Map<String, Object> param) throws Exception {
        return roleClient.getCsRoleListByMap(param);
    }

    public Integer getCsRoleCountByMap(Map<String, Object> param) throws Exception {
        return roleClient.getCsRoleCountByMap(param);
    }

    public Integer addCsRole(CsRole csRole) throws Exception {
        return roleClient.addCsRole(csRole);
    }

    public Integer modifyCsRole(CsRole csRole) throws Exception {
        return roleClient.modifyCsRole(csRole);
    }

    public Integer deleteCsRoleById(String id) throws Exception {
        return roleClient.deleteCsRoleById(id);
    }

    public Page<CsRole> queryCsRolePageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = roleClient.getCsRoleCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<CsRole> csRoleList = roleClient.getCsRoleListByMap(param);
        page.setRows(csRoleList);
        return page;
    }

    public Integer insertRoleMenusBatch(List<CsMenuRole> list, String role_id){
        return roleClient.insertRoleMenusBatch(list, role_id);
    }
}
